package com.yanyeori.framework.datasource.config;

import com.yanyeori.framework.core.util.StringUtil;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

/**
 * 系统时区配置
 *
 * @author chenkuan 2020/12/1
 */
@Slf4j
public class TimeZoneCustomizer {

    private final String timeZone;

    public TimeZoneCustomizer(String timeZone) {
        this.timeZone = timeZone;
    }

    @PostConstruct
    void started() {
        if (StringUtil.isEmpty(timeZone)) {
            return;
        }
        try {
            TimeZone.setDefault(TimeZone.getTimeZone(timeZone));
            log.debug("The current system time zone is set to: {}", timeZone);
        } catch (Exception e) {
            log.warn("TimeZone [{}] configuration is abnormal", timeZone);
        }
    }
}
